﻿// JScript File

/*Added By Dhanapal On Jan 06 2010*/

function DeleteTreeNode(obj, deleteurl, nodeText) {
    var cmsg = confirm("Are you sure you want to delete " + nodeText + " ?\r Note: Child records will also be deleted.");
    if (cmsg) {
        var tree = igtree_getTreeById("ctl00ContentPlaceHolder3UltraWebTree1");
        //alert(obj.parentNode.parentNode.tagName);

        var divobj = obj.parentNode.parentNode;
        if (divobj) {
            if (divobj.tagName.toUpperCase() == "DIV") {
                //var nodeobj = divobj;
                var nodeId = divobj.id;
                var nodeobj = igtree_getNodeById(divobj.id);
                makeAjaxCall(obj, deleteurl, nodeobj, tree);

            }
        }
    }
}



function makeAjaxCall(obj, url, node, tree){
var xmlhttp=false;
if (url == "") {
        return;
   } else {
        url += "&DeleteAjaxTreeCall= true";
    }
    
 try
 {
       // Mozilla/Safari
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        }
        // IE
        else if (window.ActiveXObject) {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
 }
 catch(E)
 {
 xmlhttp = false;
 }
 xmlhttp.open('GET', url ,true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
  //alert(xmlhttp.responseText)
    if (xmlhttp.responseText.toUpperCase() == "TRUE") {
                    node.remove(); //Removes the Node if the delete Was Successful
                    checkandappendmsg(tree);
                }
  }
 }
 xmlhttp.send(null)
 }



function checkandappendmsg(treeObj)
{
try{
    var tcnodes = treeObj.getNodes();
    
      if ( tcnodes.length <= 0 )
      {
      
      var panel = document.getElementById("ctl00_ContentPlaceHolder3_panelDynamicTree");
      panel.innerHTML = "<font class='controlFont'>No records available</font>";
      
      //alert("No Records Available");
      
      }
   
    }
  catch(ex)
    {
    
    }
}

/* function removeChildNode (node) 
    {
    
     if (node) 
    {
        var cnodes = node.getChildNodes();
        if (cnodes.length == 0)
            return;
                
        var cnode = cnodes[cnodes.length - 1];
        cnode.remove();
    }

}*/

 
  